package com.test.neo4j.Mapper;

import com.test.neo4j.Entity.Person;
import com.test.neo4j.Entity.PersonRelationShip;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

@Repository
public interface PersonRepository extends Neo4jRepository<Person, Long> {
    @Query(value = "MATCH (n:Person {name:$name}) delete n")
    public void deleteByName(String name);

    @Query(value = "MATCH (n:Person {name:$name})set n.name=$newName")
    public void updateNameByName(String name, String newName);

    @Query("MATCH (a:Person{name:$from})" +
            "MATCH (b:Person{name:$to}) " +
            "CREATE (a) - [r:PersonRelationShip{relation:$relation,description:$description,name:$name}] -> (b)")
    void relevance(String from, String relation,String  description,String name, String to);

    @Query("MATCH (startNode)-[r]->(relatedNode)" +
            "WHERE id(startNode) = $id " +
            "RETURN startNode, r, relatedNode, type(r) AS relType")
    List<Object> getRelateNodeAndRelationById(Long id);

    @Query("MATCH (startNode)-[r]->(relatedNode)" +
            "WHERE id(startNode) = $id " +
            "RETURN startNode, relatedNode")
    List<Person> getRelateNodeByStartNodeId(Long id);

//    @Query("MATCH (startNode)-[r]->(relatedNode)" +
//            "WHERE startNode.id = $id " +
//            "RETURN r")
//    List<Object> getRelateRelByStartNodeId(Long id);
}
